<template>
  <a-layout>

    <a-layout>
      <a-layout-sider width="200" style="background: #fff">
        <a-menu
            mode="inline"
            v-model:selectedKeys="selectedKeys2"
            v-model:openKeys="openKeys"
            :style="{ height: '100%', borderRight: 0 }"
        >
          <a-sub-menu key="sub1">
            <template #title>
              <span>
                <user-outlined />
                subnav 1
              </span>
            </template>
            <a-menu-item key="1">option1</a-menu-item>
            <a-menu-item key="2">option2</a-menu-item>
            <a-menu-item key="3">option3</a-menu-item>
            <a-menu-item key="4">option4</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub2">
            <template #title>
              <span>
                <laptop-outlined />
                subnav 2
              </span>
            </template>
            <a-menu-item key="5">option5</a-menu-item>
            <a-menu-item key="6">option6</a-menu-item>
            <a-menu-item key="7">option7</a-menu-item>
            <a-menu-item key="8">option8</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub3">
            <template #title>
              <span>
                <notification-outlined />
                subnav 3
              </span>
            </template>
            <a-menu-item key="9">option9</a-menu-item>
            <a-menu-item key="10">option10</a-menu-item>
            <a-menu-item key="11">option11</a-menu-item>
            <a-menu-item key="12">option12</a-menu-item>
          </a-sub-menu>
        </a-menu>
      </a-layout-sider>

        <a-layout-content
            :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
        >
          {{ebooks}}
        </a-layout-content>
    </a-layout>

  </a-layout>
</template>
<script lang="ts">
interface Ebook {
  id: number;
  name: string;
  // 其他实际属性，比如封面、分类等
  cover?: string;
  category?: string;
}
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons-vue';
// 引入 Vue 相关的组合式 API 和 defineComponent 用于定义组件
import { defineComponent, ref, onMounted, reactive, toRef } from 'vue';
// 引入 Axios 用于发起 HTTP 请求
import axios from 'axios';

// 使用 defineComponent 定义组件，明确类型推导，适用于 TypeScript 环境
export default defineComponent({
  // 注册要使用的 Ant Design Vue 图标组件
  components: {
    UserOutlined,
    LaptopOutlined,
    NotificationOutlined
  },
  setup() {
    let ebooks = ref();
    console.log("setup");
    onMounted(() => {
      // 标记 onMounted 阶段执行
      console.log("onMounted");
      // 使用 Axios 发起 GET 请求，这里的地址根据实际后端接口调整
      axios.get("http://localhost:8082/ebook/list?name=Spring")
          .then(function (response) {
            const data = response.data;
            ebooks.value = data.content;
            console.log(response);
          })
          .catch(function (error) {
            // 若请求出错，在控制台打印错误信息
            console.log(error);
          });
    });
    return {
      ebooks,
    };
  }
});
</script>
<style>
#components-layout-demo-top-side-2 .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}

.ant-row-rtl #components-layout-demo-top-side-2 .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}
</style>
